<div class="layuimini-main">
    <form class="layui-form" action="" lay-filter="edit">
        <input id="edit_info_id" type="hidden" name="edit_info_id"/>
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">必选项目</label>
                <div class="layui-input-block">

                    <div class="layui-row layui-col-space8">

                        <div class="layui-col-md2">
                            <input type="checkbox" name="groupId" title="组别" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="eventPriceId" title="赛事套餐" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="name" title="姓名" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="sex" title="性别" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="documentType" title="证件类型" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="documentNum" title="证件号码" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="province" title="省" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="city" title="市" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="area" title="区县" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="addr" title="地址" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="personalMobile" title="个人联系电话" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="emergencyContactName" title="紧急联系人" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="emergencyContactMobile" title="紧急人联系电话" checked="">
                        </div>
                    </div>

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">可选项目</label>
                <div class="layui-input-block">

                    <div class="layui-row layui-col-space8">
                        <div class="layui-col-md2">
                            <input type="checkbox" name="reference" title="推荐人" checked="">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="teamId" title="团队">
                        </div>

                        <div class="layui-col-md2">
                            <input type="checkbox" name="roleId" title="角色">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="nationality" title="国籍">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="birthday" title="生日">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="bloodType" title="血型">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="clothingSize" title="衣服尺寸">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="country" title="国家">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="nation" title="民族">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="passedPhysicalExam" title="是否通过体检">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="trainingMileage" title="训练里程">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="alumniId" title="校友会">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="alumniRelationPersion" title="校友联系人">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="education" title="学历">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="email" title="邮箱">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="occupation" title="职业">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="companyName" title="公司名称">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="companyPosition" title="公司职务">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="eventsInRecentYear" title="最近比赛">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="bestResult" title="最好成绩">
                        </div>
                        <div class="layui-col-md2">
                            <input type="checkbox" name="pic" title="成绩截图">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </form>
</div>

<script>

    let editData = {
        "teamId": false,
        "roleId": false,
        "nationality": false,
        "birthday": false,
        "bloodType": false,
        "clothingSize": false,
        "country": false,
        "nation": false,
        "passedPhysicalExam": false,
        "trainingMileage": false,
        "reference":false,
        "email": false,
        "occupation": false,
        "education": false,
        "companyName": false,
        "companyPosition": false,
        "eventsInRecentYear": false,
        "bestResult": false,
        "pic": false,
        "alumniId": false,
        "alumniRelationPersion": false,
    }

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        form.render()
        loadIndex = layer.load(1, {
            shade: [0.5, '#fff']
        });
        setTimeout(function () {
            var edit_id = document.getElementById("edit_info_id").value
            console.log("run")
            if (undefined !== edit_id && '' !== edit_id) {
                $.ajax({
                    url: "participant/page/param/get/by/eventId?eventId=" + parseInt(edit_id),
                    method: "post",
                    contentType: "application/json",
                    dataType: "json",
                    async: false,
                    success: function (res) {
                        if (res.status === 1) {
                            layer.close(loadIndex);
                            let resultData = res.data.paramJson;
                            let parse = JSON.parse(resultData);
                            console.log(parse)
                            if (parse.reference == true) {
                                $("input[name='reference']").prop("checked", true);
                            }
                            if (parse.teamId == true) {
                                $("input[name='teamId']").prop("checked", true);
                            }
                            if (parse.roleId == true) {
                                $("input[name='roleId']").prop("checked", true);
                            }
                            if (parse.nationality == true) {
                                $("input[name='nationality']").prop("checked", true);
                            }
                            if (parse.birthday == true) {
                                $("input[name='birthday']").prop("checked", true);
                            }
                            if (parse.bloodType == true) {
                                $("input[name='bloodType']").prop("checked", true);
                            }
                            if (parse.clothingSize == true) {
                                $("input[name='clothingSize']").prop("checked", true);
                            }
                            if (parse.country == true) {
                                $("input[name='country']").prop("checked", true);
                            }
                            if (parse.nation == true) {
                                $("input[name='nation']").prop("checked", true);
                            }
                            if (parse.passedPhysicalExam == true) {
                                $("input[name='passedPhysicalExam']").prop("checked", true);
                            }
                            if (parse.trainingMileage == true) {
                                $("input[name='trainingMileage']").prop("checked", true);
                            }
                            if (parse.education == true) {
                                $("input[name='education']").prop("checked", true);
                            }
                            if (parse.email == true) {
                                $("input[name='email']").prop("checked", true);
                            }
                            if (parse.occupation == true) {
                                $("input[name='occupation']").prop("checked", true);
                            }
                            if (parse.companyName == true) {
                                $("input[name='companyName']").prop("checked", true);
                            }
                            if (parse.companyPosition == true) {
                                $("input[name='companyPosition']").prop("checked", true);
                            }
                            if (parse.eventsInRecentYear == true) {
                                $("input[name='eventsInRecentYear']").prop("checked", true);
                            }
                            if (parse.bestResult == true) {
                                $("input[name='bestResult']").prop("checked", true);
                            }
                            if (parse.pic == true) {
                                $("input[name='pic']").prop("checked", true);
                            }
                            if (parse.alumniId == true) {
                                $("input[name='alumniId']").prop("checked", true);
                            }
                            if (parse.alumniRelationPersion == true) {
                                $("input[name='alumniRelationPersion']").prop("checked", true);
                            }
                            if (parse.reference == true) {
                                $("input[name='refrence']").prop("checked", true);
                            }

                            form.render('checkbox');
                        } else {
                            layer.close(loadIndex);
                        }
                    }
                })
            }
        }, 1000)


        form.on('submit(saveBtn)', function (data) {
            let pageData = data.field;

            //必填项不能取消
            if (pageData.groupId === undefined) {
                layer.msg("组别必选，不能取消", {"icon": 0});
                return false;
            }

            if (pageData.eventPriceId === undefined) {
                layer.msg("赛事套餐必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.name === undefined) {
                layer.msg("姓名必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.sex === undefined) {
                layer.msg("性别必选，不能取消", {"icon": 0});
                return false;
            }

            if (pageData.documentType === undefined) {
                layer.msg("证件类型必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.documentNum === undefined) {
                layer.msg("证件号码必选，不能取消", {"icon": 0});
                return false;
            }

            if (pageData.province === undefined) {
                layer.msg("省必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.city === undefined) {
                layer.msg("市必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.area === undefined) {
                layer.msg("区县必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.addr === undefined) {
                layer.msg("地址必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.personalMobile === undefined) {
                layer.msg("个人联系电话必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.emergencyContactName === undefined) {
                layer.msg("紧急联系人必选，不能取消", {"icon": 0});
                return false;
            }
            if (pageData.emergencyContactMobile === undefined) {
                layer.msg("紧急人联系电话必选，不能取消", {"icon": 0});
                return false;
            }

            //选填项选择


            if (pageData.teamId !== undefined) {
                editData.teamId = true;
            } else {
                editData.teamId = false;
            }
            if (pageData.reference !== undefined) {
                editData.reference = true;
            } else {
                editData.reference = false;
            }

            if (pageData.roleId !== undefined) {
                editData.roleId = true;
            } else {
                editData.roleId = false;
            }
            if (pageData.nationality !== undefined) {
                editData.nationality = true;
            } else {
                editData.nationality = false;
            }
            if (pageData.birthday !== undefined) {
                editData.birthday = true;
            } else {
                editData.birthday = false;
            }
            if (pageData.bloodType !== undefined) {
                editData.bloodType = true;
            } else {
                editData.bloodType = false;
            }
            if (pageData.clothingSize !== undefined) {
                editData.clothingSize = true;
            } else {
                editData.clothingSize = false;
            }

            if (pageData.country !== undefined) {
                editData.country = true;
            } else {
                editData.country = false;
            }

            if (pageData.nation !== undefined) {
                editData.nation = true;
            } else {
                editData.nation = false;
            }
            if (pageData.passedPhysicalExam !== undefined) {
                editData.passedPhysicalExam = true;
            } else {
                editData.passedPhysicalExam = false;
            }
            if (pageData.trainingMileage !== undefined) {
                editData.trainingMileage = true;
            } else {
                editData.trainingMileage = false;
            }


            if (pageData.email !== undefined) {
                editData.email = true;
            } else {
                editData.email = false;
            }


            if (pageData.occupation !== undefined) {
                editData.occupation = true;
            } else {
                editData.occupation = false;
            }

            if (pageData.education !== undefined) {
                editData.education = true;
            } else {
                editData.education = false;
            }


            if (pageData.companyName !== undefined) {
                editData.companyName = true;
            } else {
                editData.companyName = false;
            }


            if (pageData.companyPosition !== undefined) {
                editData.companyPosition = true;
            } else {
                editData.companyPosition = false;
            }


            if (pageData.eventsInRecentYear !== undefined) {
                editData.eventsInRecentYear = true;
            } else {
                editData.eventsInRecentYear = false;
            }


            if (pageData.bestResult !== undefined) {
                editData.bestResult = true;
            } else {
                editData.bestResult = false;
            }


            if (pageData.pic !== undefined) {
                editData.pic = true;
            } else {
                editData.pic = false;
            }

            if (pageData.alumniId !== undefined) {
                editData.alumniId = true;
            } else {
                editData.alumniId = false;
            }


            if (pageData.alumniRelationPersion !== undefined) {
                editData.alumniRelationPersion = true;
            } else {
                editData.alumniRelationPersion = false;
            }


            var edit_id = document.getElementById("edit_info_id").value


            let param = {
                "eventInformationId": parseInt(edit_id),
                "paramJson": editData
            }
            $.ajax({
                url: "participant/page/param/add",
                method: "post",
                contentType: "application/json",
                dataType: "json",
                async: false,
                data: JSON.stringify(param),
                success: function (res) {

                    if (res.status === 1) {
                        layer.alert("成功", {icon: 1});

                    } else {
                        layer.alert("失败", {icon: 2});
                    }
                }
            })
            return false;
        });
        form.render();

    });


</script>